import { defineStore } from 'pinia'
import { ref } from 'vue'
import { get_dict_code, get_org_type_dict } from '@/api/api'
// import { Sm4encrypt, Sm4Dncrypt } from '@/utils/encryption.js'

import { sessionMemory } from '@/utils/sessionMemory'

export const dictStore = defineStore('dictCode', () => {
  const dict = ref(sessionMemory.getItem('dictTree'))
  /* 获取系统字典信息*/
  const getDict = async () => {
    clearDict()
    const res = await get_dict_code()
    if (res.status == 200 && res.data && res.data.length > 0) {
      dict.value = res.data[0].children
      sessionMemory.setItem('dictTree', res.data[0].children)
      return true
    } else {
      return false
    }

  }

  const clearDict = () => {
    sessionMemory.setItem('dictTree', [])
    dict.value = []
  }


  return {
    getDict,
    clearDict,
    dict
  }
})
